<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-20
 * @package TinPhp
 */
if (!defined('IN_TINPHP')) {
	exit ('Access Denied');
}
require_once("exception/TypeException.php");
/**
 * Module type definitions
 */
class Module {
  const LOGIC   = 1;
  const VIEW    = 2;
  const DAO     = 3;
}
/** 项目加载类工厂 */
class ModuleFactory {

  /** 加载指定的类，并存创建类对象，类必须存在与/app目录下
   * @param string $type 类所在文件夹名称
   * @param string $className 类名称
   */
  public static function load($type, $className) {
    $typeName = "";
    switch ($type) {
    case Module::LOGIC:
      $typeName = "logic"; 
      break;
    case Module::VIEW:
      $typeName = "view"; 
      break;
    default:
      throw new TypeException("Module type of '" . $type ."' can't be found.");
    }

    if (require_once TIN_APP_PATH . "app/" . $typeName  . "/" . $className . ".php") {
      return new $className;
    } else {
      throw new TypeException ('class not found');
    }
  }
}
?>
